package leetcode_cn;

/**
 * 删除排序数组中重复的元素
 *
 * @author briarbear
 * @blog https://briarbear.github.io
 * @date 2018-09-06 15:28
 */
public class RemoveDuplicates {


    public int solution(int[] nums){
        if (nums == null || nums.length == 0) return 0;
        int len = nums.length;
        int pre = nums[0],res = 0,index = 0;
        for (int i = 1; i < len; i++) {
            if (nums[i] == pre){
                pre = nums[i];
                continue;
            }
            nums[++index] = nums[i];
            pre = nums[i];
        }

        return index+1;
    }

    public static void main(String[] args) {
        System.out.println(new RemoveDuplicates().solution(new int[]{0, 0, 1, 1, 1, 2, 2, 3, 3, 4}));
    }
}
